package org.hhchat.others;

import java.util.*;

/**
 * Created by HMH on 2017/3/29.
 */
public class test3 {

    static int min=99999;
    public static int dfs(int target, List<Integer> fruits,int cost) {
        if (target < 0 ) {
            return 1;
        }
        if(cost >= min){
            return 2;
        }
        if (target == 0) {
            min = cost;
            return 2;
        }
        for(int i=fruits.size()-1;i>=0;i--) {
            if (target >= fruits.get(i)) {
                if(dfs(target-fruits.get(i),fruits,cost+1)==2)
                    break;
                else
                {

                }
            }
        }
        return 1;
    }

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String array = scanner.next();
        int num = scanner.nextInt();
        String[] fruitstr = array.split(",");
        List<Integer> fruits = new ArrayList<>();
        for (int i=0;i<fruitstr.length;i++) {
            fruits.add( Integer.parseInt(fruitstr[i]));
        }
        Collections.sort(fruits);
        dfs(num,fruits,0);
        if(min==99999)  min = -1;
        System.out.println(min);
    }
}
